home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 8 / The Arsenal Files Collection #8 (Arsenal Computer) (1996).ISO / g_quake / telew11.zip / WEAPONS.QC < prev   
Text File  |  1996-08-28  |  26KB  |  1,243 lines

  1. /*
  2. */
  3. void (entity targ, entity inflictor, entity attacker, float damage) T_Damage;
  4. void () player_run;
  5. void(entity bomb, entity attacker, float rad, entity ignore) T_RadiusDamage;
  6. void(vector org, vector vel, float damage) SpawnBlood;
  7. void() SuperDamageSound;
  8.  
  9. /* Added for TeleWeapon Patch */
  10. void(entity bomb, entity attacker, float dam, float rad, entity ignore) T_WaterRadiusDamage;
  11. /* End */
  12.  
  13. // called by worldspawn
  14. void() W_Precache =
  15. {
  16.     precache_sound ("weapons/r_exp3.wav");    // new rocket explosion
  17.     precache_sound ("weapons/rocket1i.wav");    // spike gun
  18.     precache_sound ("weapons/sgun1.wav");
  19.     precache_sound ("weapons/guncock.wav");    // player shotgun
  20.     precache_sound ("weapons/ric1.wav");    // ricochet (used in c code)
  21.     precache_sound ("weapons/ric2.wav");    // ricochet (used in c code)
  22.     precache_sound ("weapons/ric3.wav");    // ricochet (used in c code)
  23.     precache_sound ("weapons/spike2.wav");    // super spikes
  24.     precache_sound ("weapons/tink1.wav");    // spikes tink (used in c code)
  25.     precache_sound ("weapons/grenade.wav");    // grenade launcher
  26.     precache_sound ("weapons/bounce.wav");        // grenade bounce
  27.     precache_sound ("weapons/shotgn2.wav");    // super shotgun
  28. };
  29.  
  30. float() crandom =
  31. {
  32.     return 2*(random() - 0.5);
  33. };
  34.  
  35. /*
  36. ================
  37. W_FireAxe
  38. ================
  39. */
  40. void() W_FireAxe =
  41. {
  42.     local    vector    source;
  43.     local    vector    org;
  44.  
  45.     source = self.origin + '0 0 16';
  46.     traceline (source, source + v_forward*64, FALSE, self);
  47.     if (trace_fraction == 1.0)
  48.         return;
  49.     
  50.     org = trace_endpos - v_forward*4;
  51.  
  52.     if (trace_ent.takedamage)
  53.     {
  54.         trace_ent.axhitme = 1;
  55.         SpawnBlood (org, '0 0 0', 20);
  56.         T_Damage (trace_ent, self, self, 20);
  57.     }
  58.     else
  59.     {    // hit wall
  60.         sound (self, CHAN_WEAPON, "player/axhit2.wav", 1, ATTN_NORM);
  61.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  62.         WriteByte (MSG_BROADCAST, TE_GUNSHOT);
  63.         WriteCoord (MSG_BROADCAST, org_x);
  64.         WriteCoord (MSG_BROADCAST, org_y);
  65.         WriteCoord (MSG_BROADCAST, org_z);
  66.     }
  67. };
  68.  
  69.  
  70. //============================================================================
  71.  
  72.  
  73. vector() wall_velocity =
  74. {
  75.     local vector    vel;
  76.     
  77.     vel = normalize (self.velocity);
  78.     vel = normalize(vel + v_up*(random()- 0.5) + v_right*(random()- 0.5));
  79.     vel = vel + 2*trace_plane_normal;
  80.     vel = vel * 200;
  81.     
  82.     return vel;
  83. };
  84.  
  85.  
  86. /*
  87. ================
  88. SpawnMeatSpray
  89. ================
  90. */
  91. void(vector org, vector vel) SpawnMeatSpray =
  92. {
  93.     local    entity missile, mpuff;
  94.     local    vector    org;
  95.  
  96.     missile = spawn ();
  97.     missile.owner = self;
  98.     missile.movetype = MOVETYPE_BOUNCE;
  99.     missile.solid = SOLID_NOT;
  100.  
  101.     makevectors (self.angles);
  102.  
  103.     missile.velocity = vel;
  104.     missile.velocity_z = missile.velocity_z + 250 + 50*random();
  105.  
  106.     missile.avelocity = '3000 1000 2000';
  107.     
  108. // set missile duration
  109.     missile.nextthink = time + 1;
  110.     missile.think = SUB_Remove;
  111.  
  112.     setmodel (missile, "progs/zom_gib.mdl");
  113.     setsize (missile, '0 0 0', '0 0 0');        
  114.     setorigin (missile, org);
  115. };
  116.  
  117. /*
  118. ================
  119. SpawnBlood
  120. ================
  121. */
  122. void(vector org, vector vel, float damage) SpawnBlood =
  123. {
  124.     particle (org, vel*0.1, 73, damage*2);
  125. };
  126.  
  127. /*
  128. ================
  129. spawn_touchblood
  130. ================
  131. */
  132. void(float damage) spawn_touchblood =
  133. {
  134.     local vector    vel;
  135.  
  136.     vel = wall_velocity () * 0.2;
  137.     SpawnBlood (self.origin + vel*0.01, vel, damage);
  138. };
  139.  
  140.  
  141. /*
  142. ================
  143. SpawnChunk
  144. ================
  145. */
  146. void(vector org, vector vel) SpawnChunk =
  147. {
  148.     particle (org, vel*0.02, 0, 10);
  149. };
  150.  
  151. /*
  152. ==============================================================================
  153.  
  154. MULTI-DAMAGE
  155.  
  156. Collects multiple small damages into a single damage
  157.  
  158. ==============================================================================
  159. */
  160.  
  161. entity    multi_ent;
  162. float    multi_damage;
  163.  
  164. void() ClearMultiDamage =
  165. {
  166.     multi_ent = world;
  167.     multi_damage = 0;
  168. };
  169.  
  170. void() ApplyMultiDamage =
  171. {
  172.     if (!multi_ent)
  173.         return;
  174.     T_Damage (multi_ent, self, self, multi_damage);
  175. };
  176.  
  177. void(entity hit, float damage) AddMultiDamage =
  178. {
  179.     if (!hit)
  180.         return;
  181.     
  182.     if (hit != multi_ent)
  183.     {
  184.         ApplyMultiDamage ();
  185.         multi_damage = damage;
  186.         multi_ent = hit;
  187.     }
  188.     else
  189.         multi_damage = multi_damage + damage;
  190. };
  191.  
  192. /*
  193. ==============================================================================
  194.  
  195. BULLETS
  196.  
  197. ==============================================================================
  198. */
  199.  
  200. /*
  201. ================
  202. TraceAttack
  203. ================
  204. */
  205. void(float damage, vector dir) TraceAttack =
  206. {
  207.     local    vector    vel, org;
  208.     
  209.     vel = normalize(dir + v_up*crandom() + v_right*crandom());
  210.     vel = vel + 2*trace_plane_normal;
  211.     vel = vel * 200;
  212.  
  213.     org = trace_endpos - dir*4;
  214.  
  215.     if (trace_ent.takedamage)
  216.     {
  217.         SpawnBlood (org, vel*0.2, damage);
  218.         AddMultiDamage (trace_ent, damage);
  219.     }
  220.     else
  221.     {
  222.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  223.         WriteByte (MSG_BROADCAST, TE_GUNSHOT);
  224.         WriteCoord (MSG_BROADCAST, org_x);
  225.         WriteCoord (MSG_BROADCAST, org_y);
  226.         WriteCoord (MSG_BROADCAST, org_z);
  227.     }
  228. };
  229.  
  230. /*
  231. ================
  232. FireBullets
  233.  
  234. Used by shotgun, super shotgun, and enemy soldier firing
  235. Go to the trouble of combining multiple pellets into a single damage call.
  236. ================
  237. */
  238. void(float shotcount, vector dir, vector spread) FireBullets =
  239. {
  240.     local    vector direction;
  241.     local    vector    src;
  242.     
  243.     makevectors(self.v_angle);
  244.  
  245.     src = self.origin + v_forward*10;
  246.     src_z = self.absmin_z + self.size_z * 0.7;
  247.  
  248.     ClearMultiDamage ();
  249.     while (shotcount > 0)
  250.     {
  251.         direction = dir + crandom()*spread_x*v_right + crandom()*spread_y*v_up;
  252.  
  253.         traceline (src, src + direction*2048, FALSE, self);
  254.         if (trace_fraction != 1.0)
  255.             TraceAttack (4, direction);
  256.  
  257.         shotcount = shotcount - 1;
  258.     }
  259.     ApplyMultiDamage ();
  260. };
  261.  
  262. /*
  263. ================
  264. W_FireShotgun
  265. ================
  266. */
  267. void() W_FireShotgun =
  268. {
  269.     local vector dir;
  270.  
  271.     sound (self, CHAN_WEAPON, "weapons/guncock.wav", 1, ATTN_NORM);    
  272.  
  273.     self.punchangle_x = -2;
  274.     
  275.     self.currentammo = self.ammo_shells = self.ammo_shells - 1;
  276.     dir = aim (self, 100000);
  277.     FireBullets (6, dir, '0.04 0.04 0');
  278. };
  279.  
  280.  
  281. /*
  282. ================
  283. W_FireSuperShotgun
  284. ================
  285. */
  286. void() W_FireSuperShotgun =
  287. {
  288.     local vector dir;
  289.  
  290.     if (self.currentammo == 1)
  291.     {
  292.         W_FireShotgun ();
  293.         return;
  294.     }
  295.         
  296.     sound (self ,CHAN_WEAPON, "weapons/shotgn2.wav", 1, ATTN_NORM);    
  297.  
  298.     self.punchangle_x = -4;
  299.     
  300.     self.currentammo = self.ammo_shells = self.ammo_shells - 2;
  301.     dir = aim (self, 100000);
  302.     FireBullets (14, dir, '0.14 0.08 0');
  303. };
  304.  
  305.  
  306. /*
  307. ==============================================================================
  308.  
  309. ROCKETS
  310.  
  311. ==============================================================================
  312. */
  313.  
  314. void()    s_explode1    =    [0,        s_explode2] {};
  315. void()    s_explode2    =    [1,        s_explode3] {};
  316. void()    s_explode3    =    [2,        s_explode4] {};
  317. void()    s_explode4    =    [3,        s_explode5] {};
  318. void()    s_explode5    =    [4,        s_explode6] {};
  319. void()    s_explode6    =    [5,        SUB_Remove] {};
  320.  
  321. void() BecomeExplosion =
  322. {
  323.     self.movetype = MOVETYPE_NONE;
  324.     self.velocity = '0 0 0';
  325.     self.touch = SUB_Null;
  326.     setmodel (self, "progs/s_explod.spr");
  327.     self.solid = SOLID_NOT;
  328.     s_explode1 ();
  329. };
  330.  
  331. void() T_MissileTouch =
  332. {
  333.     local float    damg;
  334.  
  335.     if (other == self.owner)
  336.         return;        // don't explode on owner
  337.  
  338.     if (pointcontents(self.origin) == CONTENT_SKY)
  339.     {
  340.         remove(self);
  341.         return;
  342.     }
  343.  
  344.     damg = 100 + random()*20;
  345.     
  346.     if (other.health)
  347.     {
  348.         if (other.classname == "monster_shambler")
  349.             damg = damg * 0.5;    // mostly immune
  350.         T_Damage (other, self, self.owner, damg );
  351.     }
  352.  
  353.     // don't do radius damage to the other, because all the damage
  354.     // was done in the impact
  355.     T_RadiusDamage (self, self.owner, 120, other);
  356.  
  357. //    sound (self, CHAN_WEAPON, "weapons/r_exp3.wav", 1, ATTN_NORM);
  358.     self.origin = self.origin - 8*normalize(self.velocity);
  359.  
  360.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  361.     WriteByte (MSG_BROADCAST, TE_EXPLOSION);
  362.     WriteCoord (MSG_BROADCAST, self.origin_x);
  363.     WriteCoord (MSG_BROADCAST, self.origin_y);
  364.     WriteCoord (MSG_BROADCAST, self.origin_z);
  365.  
  366.     BecomeExplosion ();
  367. };
  368.  
  369.  
  370.  
  371. /*
  372. ================
  373. W_FireRocket
  374. ================
  375. */
  376. void() W_FireRocket =
  377. {
  378.     local    entity missile, mpuff;
  379.     
  380.     self.currentammo = self.ammo_rockets = self.ammo_rockets - 1;
  381.     
  382.     sound (self, CHAN_WEAPON, "weapons/sgun1.wav", 1, ATTN_NORM);
  383.  
  384.     self.punchangle_x = -2;
  385.  
  386.     missile = spawn ();
  387.     missile.owner = self;
  388.     missile.movetype = MOVETYPE_FLYMISSILE;
  389.     missile.solid = SOLID_BBOX;
  390.         
  391. // set missile speed    
  392.  
  393.     makevectors (self.v_angle);
  394.     missile.velocity = aim(self, 1000);
  395.     missile.velocity = missile.velocity * 1000;
  396.     missile.angles = vectoangles(missile.velocity);
  397.     
  398.     missile.touch = T_MissileTouch;
  399.     
  400. // set missile duration
  401.     missile.nextthink = time + 5;
  402.     missile.think = SUB_Remove;
  403.  
  404.     setmodel (missile, "progs/missile.mdl");
  405.     setsize (missile, '0 0 0', '0 0 0');        
  406.     setorigin (missile, self.origin + v_forward*8 + '0 0 16');
  407. };
  408.  
  409. /*
  410. ===============================================================================
  411.  
  412. LIGHTNING
  413.  
  414. ===============================================================================
  415. */
  416.  
  417. /*
  418. =================
  419. LightningDamage
  420. =================
  421. */
  422. void(vector p1, vector p2, entity from, float damage) LightningDamage =
  423. {
  424.     local entity        e1, e2;
  425.     local vector        f;
  426.     
  427.     f = p2 - p1;
  428.     normalize (f);
  429.     f_x = 0 - f_y;
  430.     f_y = f_x;
  431.     f_z = 0;
  432.     f = f*16;
  433.  
  434.     e1 = e2 = world;
  435.  
  436.     traceline (p1, p2, FALSE, self);
  437.     if (trace_ent.takedamage)
  438.     {
  439.         particle (trace_endpos, '0 0 100', 225, damage*4);
  440.         T_Damage (trace_ent, from, from, damage);
  441.         if (self.classname == "player")
  442.         {
  443.             if (other.classname == "player")
  444.                 trace_ent.velocity_z = trace_ent.velocity_z + 400;
  445.         }
  446.     }
  447.     e1 = trace_ent;
  448.  
  449.     traceline (p1 + f, p2 + f, FALSE, self);
  450.     if (trace_ent != e1 && trace_ent.takedamage)
  451.     {
  452.         particle (trace_endpos, '0 0 100', 225, damage*4);
  453.         T_Damage (trace_ent, from, from, damage);
  454.     }
  455.     e2 = trace_ent;
  456.  
  457.     traceline (p1 - f, p2 - f, FALSE, self);
  458.     if (trace_ent != e1 && trace_ent != e2 && trace_ent.takedamage)
  459.     {
  460.         particle (trace_endpos, '0 0 100', 225, damage*4);
  461.         T_Damage (trace_ent, from, from, damage);
  462.     }
  463. };
  464.  
  465.  
  466. void() W_FireLightning =
  467. {
  468.     local    vector        org;
  469.         local   vector          tempvect;
  470.  
  471.     if (self.ammo_cells < 1)
  472.     {
  473.         self.weapon = W_BestWeapon ();
  474.         W_SetCurrentAmmo ();
  475.         return;
  476.     }
  477.  
  478. // explode if under water
  479.     if (self.waterlevel > 1)
  480.     {
  481. /* Modified for TeleWeapon Patch
  482.    Players near, but not in, water will not be harmed by discharges.
  483. */
  484.                 T_WaterRadiusDamage (self, self, 35*self.ammo_cells, (35*self.ammo_cells)+40, world);
  485. /* End */
  486.         self.ammo_cells = 0;
  487.         W_SetCurrentAmmo ();
  488.         return;
  489.     }
  490.  
  491.     if (self.t_width < time)
  492.     {
  493.         sound (self, CHAN_WEAPON, "weapons/lhit.wav", 1, ATTN_NORM);
  494.         self.t_width = time + 0.6;
  495.     }
  496.     self.punchangle_x = -2;
  497.  
  498.     self.currentammo = self.ammo_cells = self.ammo_cells - 1;
  499.  
  500.     org = self.origin + '0 0 16';
  501.     
  502.     traceline (org, org + v_forward*600, TRUE, self);
  503.  
  504.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  505.     WriteByte (MSG_BROADCAST, TE_LIGHTNING2);
  506.     WriteEntity (MSG_BROADCAST, self);
  507.     WriteCoord (MSG_BROADCAST, org_x);
  508.     WriteCoord (MSG_BROADCAST, org_y);
  509.     WriteCoord (MSG_BROADCAST, org_z);
  510.     WriteCoord (MSG_BROADCAST, trace_endpos_x);
  511.     WriteCoord (MSG_BROADCAST, trace_endpos_y);
  512.     WriteCoord (MSG_BROADCAST, trace_endpos_z);
  513.  
  514. /* Added for TeleWeapon Patch */
  515. /* If shooting into the water (while not touching it), make
  516.    all players in water take some damage
  517. */
  518.         if ((trace_inwater) && (!self.waterlevel))
  519.         {
  520.                 tempvect = self.origin;
  521.                 self.origin = trace_endpos;
  522.  
  523.                 T_WaterRadiusDamage (self, self, 1, 400, self);
  524.                 self.origin = tempvect;
  525.         } else
  526. /* End */
  527.                 LightningDamage (self.origin, trace_endpos + v_forward*4, self, 30);
  528. };
  529.  
  530.  
  531. //=============================================================================
  532.  
  533.  
  534. void() GrenadeExplode =
  535. {
  536.     T_RadiusDamage (self, self.owner, 120, world);
  537.  
  538.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  539.     WriteByte (MSG_BROADCAST, TE_EXPLOSION);
  540.     WriteCoord (MSG_BROADCAST, self.origin_x);
  541.     WriteCoord (MSG_BROADCAST, self.origin_y);
  542.     WriteCoord (MSG_BROADCAST, self.origin_z);
  543.  
  544.     BecomeExplosion ();
  545. };
  546.  
  547. void() GrenadeTouch =
  548. {
  549.     if (other == self.owner)
  550.         return;        // don't explode on owner
  551.     if (other.takedamage == DAMAGE_AIM)
  552.     {
  553.         GrenadeExplode();
  554.         return;
  555.     }
  556.     sound (self, CHAN_WEAPON, "weapons/bounce.wav", 1, ATTN_NORM);    // bounce sound
  557.     if (self.velocity == '0 0 0')
  558.         self.avelocity = '0 0 0';
  559. };
  560.  
  561. /*
  562. ================
  563. W_FireGrenade
  564. ================
  565. */
  566. void() W_FireGrenade =
  567. {
  568.     local    entity missile, mpuff;
  569.     
  570.     self.currentammo = self.ammo_rockets = self.ammo_rockets - 1;
  571.     
  572.     sound (self, CHAN_WEAPON, "weapons/grenade.wav", 1, ATTN_NORM);
  573.  
  574.     self.punchangle_x = -2;
  575.  
  576.     missile = spawn ();
  577.     missile.owner = self;
  578.     missile.movetype = MOVETYPE_BOUNCE;
  579.     missile.solid = SOLID_BBOX;
  580.     missile.classname = "grenade";
  581.         
  582. // set missile speed    
  583.  
  584.     makevectors (self.v_angle);
  585.  
  586.     if (self.v_angle_x)
  587.         missile.velocity = v_forward*600 + v_up * 200 + crandom()*v_right*10 + crandom()*v_up*10;
  588.     else
  589.     {
  590.         missile.velocity = aim(self, 10000);
  591.         missile.velocity = missile.velocity * 600;
  592.         missile.velocity_z = 200;
  593.     }
  594.  
  595.     missile.avelocity = '300 300 300';
  596.  
  597.     missile.angles = vectoangles(missile.velocity);
  598.     
  599.     missile.touch = GrenadeTouch;
  600.     
  601. // set missile duration
  602.     missile.nextthink = time + 2.5;
  603.     missile.think = GrenadeExplode;
  604.  
  605.     setmodel (missile, "progs/grenade.mdl");
  606.     setsize (missile, '0 0 0', '0 0 0');        
  607.     setorigin (missile, self.origin);
  608. };
  609.  
  610.  
  611. //=============================================================================
  612.  
  613. void() spike_touch;
  614. void() superspike_touch;
  615.  
  616.  
  617. /*
  618. ===============
  619. launch_spike
  620.  
  621. Used for both the player and the ogre
  622. ===============
  623. */
  624. void(vector org, vector dir) launch_spike =
  625. {
  626.     newmis = spawn ();
  627.     newmis.owner = self;
  628.     newmis.movetype = MOVETYPE_FLYMISSILE;
  629.     newmis.solid = SOLID_BBOX;
  630.  
  631.     newmis.angles = vectoangles(dir);
  632.     
  633.     newmis.touch = spike_touch;
  634.     newmis.classname = "spike";
  635.     newmis.think = SUB_Remove;
  636.     newmis.nextthink = time + 6;
  637.     setmodel (newmis, "progs/spike.mdl");
  638.     setsize (newmis, VEC_ORIGIN, VEC_ORIGIN);        
  639.     setorigin (newmis, org);
  640.  
  641.     newmis.velocity = dir * 1000;
  642. };
  643.  
  644. void() W_FireSuperSpikes =
  645. {
  646.     local vector    dir;
  647.     local entity    old;
  648.     
  649.     sound (self, CHAN_WEAPON, "weapons/spike2.wav", 1, ATTN_NORM);
  650.     self.attack_finished = time + 0.2;
  651.     self.currentammo = self.ammo_nails = self.ammo_nails - 2;
  652.     dir = aim (self, 1000);
  653.     launch_spike (self.origin + '0 0 16', dir);
  654.     newmis.touch = superspike_touch;
  655.     setmodel (newmis, "progs/s_spike.mdl");
  656.     setsize (newmis, VEC_ORIGIN, VEC_ORIGIN);        
  657.     self.punchangle_x = -2;
  658. };
  659.  
  660. void(float ox) W_FireSpikes =
  661. {
  662.     local vector    dir;
  663.     local entity    old;
  664.     
  665.     makevectors (self.v_angle);
  666.     
  667.     if (self.ammo_nails >= 2 && self.weapon == IT_SUPER_NAILGUN)
  668.     {
  669.         W_FireSuperSpikes ();
  670.         return;
  671.     }
  672.  
  673.     if (self.ammo_nails < 1)
  674.     {
  675.         self.weapon = W_BestWeapon ();
  676.         W_SetCurrentAmmo ();
  677.         return;
  678.     }
  679.  
  680.     sound (self, CHAN_WEAPON, "weapons/rocket1i.wav", 1, ATTN_NORM);
  681.     self.attack_finished = time + 0.2;
  682.     self.currentammo = self.ammo_nails = self.ammo_nails - 1;
  683.     dir = aim (self, 1000);
  684.     launch_spike (self.origin + '0 0 16' + v_right*ox, dir);
  685.  
  686.     self.punchangle_x = -2;
  687. };
  688.  
  689.  
  690.  
  691. .float hit_z;
  692. void() spike_touch =
  693. {
  694. local float rand;
  695.     if (other == self.owner)
  696.         return;
  697.  
  698.     if (other.solid == SOLID_TRIGGER)
  699.         return;    // trigger field, do nothing
  700.  
  701.     if (pointcontents(self.origin) == CONTENT_SKY)
  702.     {
  703.         remove(self);
  704.         return;
  705.     }
  706.     
  707. // hit something that bleeds
  708.     if (other.takedamage)
  709.     {
  710.         spawn_touchblood (9);
  711.         T_Damage (other, self, self.owner, 9);
  712.     }
  713.     else
  714.     {
  715.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  716.         
  717.         if (self.classname == "wizspike")
  718.             WriteByte (MSG_BROADCAST, TE_WIZSPIKE);
  719.         else if (self.classname == "knightspike")
  720.             WriteByte (MSG_BROADCAST, TE_KNIGHTSPIKE);
  721.         else
  722.             WriteByte (MSG_BROADCAST, TE_SPIKE);
  723.         WriteCoord (MSG_BROADCAST, self.origin_x);
  724.         WriteCoord (MSG_BROADCAST, self.origin_y);
  725.         WriteCoord (MSG_BROADCAST, self.origin_z);
  726.     }
  727.  
  728.     remove(self);
  729.  
  730. };
  731.  
  732. void() superspike_touch =
  733. {
  734. local float rand;
  735.     if (other == self.owner)
  736.         return;
  737.  
  738.     if (other.solid == SOLID_TRIGGER)
  739.         return;    // trigger field, do nothing
  740.  
  741.     if (pointcontents(self.origin) == CONTENT_SKY)
  742.     {
  743.         remove(self);
  744.         return;
  745.     }
  746.     
  747. // hit something that bleeds
  748.     if (other.takedamage)
  749.     {
  750.         spawn_touchblood (18);
  751.         T_Damage (other, self, self.owner, 18);
  752.     }
  753.     else
  754.     {
  755.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  756.         WriteByte (MSG_BROADCAST, TE_SUPERSPIKE);
  757.         WriteCoord (MSG_BROADCAST, self.origin_x);
  758.         WriteCoord (MSG_BROADCAST, self.origin_y);
  759.         WriteCoord (MSG_BROADCAST, self.origin_z);
  760.     }
  761.  
  762.     remove(self);
  763.  
  764. };
  765.  
  766.  
  767. /*
  768. ===============================================================================
  769.  
  770. PLAYER WEAPON USE
  771.  
  772. ===============================================================================
  773. */
  774.  
  775. void() W_SetCurrentAmmo =
  776. {
  777.     player_run ();        // get out of any weapon firing states
  778.  
  779.     self.items = self.items - ( self.items & (IT_SHELLS | IT_NAILS | IT_ROCKETS | IT_CELLS) );
  780.     
  781.     if (self.weapon == IT_AXE)
  782.     {
  783.         self.currentammo = 0;
  784.         self.weaponmodel = "progs/v_axe.mdl";
  785.         self.weaponframe = 0;
  786.     }
  787.     else if (self.weapon == IT_SHOTGUN)
  788.     {
  789.         self.currentammo = self.ammo_shells;
  790.         self.weaponmodel = "progs/v_shot.mdl";
  791.         self.weaponframe = 0;
  792.         self.items = self.items | IT_SHELLS;
  793.     }
  794.     else if (self.weapon == IT_SUPER_SHOTGUN)
  795.     {
  796.         self.currentammo = self.ammo_shells;
  797.         self.weaponmodel = "progs/v_shot2.mdl";
  798.         self.weaponframe = 0;
  799.         self.items = self.items | IT_SHELLS;
  800.     }
  801.     else if (self.weapon == IT_NAILGUN)
  802.     {
  803.         self.currentammo = self.ammo_nails;
  804.         self.weaponmodel = "progs/v_nail.mdl";
  805.         self.weaponframe = 0;
  806.         self.items = self.items | IT_NAILS;
  807.     }
  808.     else if (self.weapon == IT_SUPER_NAILGUN)
  809.     {
  810.         self.currentammo = self.ammo_nails;
  811.         self.weaponmodel = "progs/v_nail2.mdl";
  812.         self.weaponframe = 0;
  813.         self.items = self.items | IT_NAILS;
  814.     }
  815.     else if (self.weapon == IT_GRENADE_LAUNCHER)
  816.     {
  817.         self.currentammo = self.ammo_rockets;
  818.         self.weaponmodel = "progs/v_rock.mdl";
  819.         self.weaponframe = 0;
  820.         self.items = self.items | IT_ROCKETS;
  821.     }
  822.     else if (self.weapon == IT_ROCKET_LAUNCHER)
  823.     {
  824.         self.currentammo = self.ammo_rockets;
  825.         self.weaponmodel = "progs/v_rock2.mdl";
  826.         self.weaponframe = 0;
  827.         self.items = self.items | IT_ROCKETS;
  828.     }
  829.     else if (self.weapon == IT_LIGHTNING)
  830.     {
  831.         self.currentammo = self.ammo_cells;
  832.         self.weaponmodel = "progs/v_light.mdl";
  833.         self.weaponframe = 0;
  834.         self.items = self.items | IT_CELLS;
  835.     }
  836.     else
  837.     {
  838.         self.currentammo = 0;
  839.         self.weaponmodel = "";
  840.         self.weaponframe = 0;
  841.     }
  842. };
  843.  
  844. float() W_BestWeapon =
  845. {
  846.     local    float    it;
  847.     
  848.     it = self.items;
  849.  
  850.     if(self.ammo_cells >= 1 && (it & IT_LIGHTNING) )
  851.         return IT_LIGHTNING;
  852.     else if(self.ammo_nails >= 2 && (it & IT_SUPER_NAILGUN) )
  853.         return IT_SUPER_NAILGUN;
  854.     else if(self.ammo_shells >= 2 && (it & IT_SUPER_SHOTGUN) )
  855.         return IT_SUPER_SHOTGUN;
  856.     else if(self.ammo_nails >= 1 && (it & IT_NAILGUN) )
  857.         return IT_NAILGUN;
  858.     else if(self.ammo_shells >= 1 && (it & IT_SHOTGUN) )
  859.         return IT_SHOTGUN;
  860.         
  861. /*
  862.     if(self.ammo_rockets >= 1 && (it & IT_ROCKET_LAUNCHER) )
  863.         return IT_ROCKET_LAUNCHER;
  864.     else if(self.ammo_rockets >= 1 && (it & IT_GRENADE_LAUNCHER) )
  865.         return IT_GRENADE_LAUNCHER;
  866.  
  867. */
  868.  
  869.     return IT_AXE;
  870. };
  871.  
  872. float() W_CheckNoAmmo =
  873. {
  874.     if (self.currentammo > 0)
  875.         return TRUE;
  876.  
  877.     if (self.weapon == IT_AXE)
  878.         return TRUE;
  879.     
  880.     self.weapon = W_BestWeapon ();
  881.  
  882.     W_SetCurrentAmmo ();
  883.     
  884. // drop the weapon down
  885.     return FALSE;
  886. };
  887.  
  888. /*
  889. ============
  890. W_Attack
  891.  
  892. An attack impulse can be triggered now
  893. ============
  894. */
  895. void()    player_axe1;
  896. void()    player_axeb1;
  897. void()    player_axec1;
  898. void()    player_axed1;
  899. void()    player_shot1;
  900. void()    player_nail1;
  901. void()    player_light1;
  902. void()    player_rocket1;
  903.  
  904. void() W_Attack =
  905. {
  906.     local    float    r;
  907.  
  908.     if (!W_CheckNoAmmo ())
  909.         return;
  910.  
  911.     makevectors    (self.v_angle);            // calculate forward angle for velocity
  912.     self.show_hostile = time + 1;    // wake monsters up
  913.  
  914.     if (self.weapon == IT_AXE)
  915.     {
  916.         sound (self, CHAN_WEAPON, "weapons/ax1.wav", 1, ATTN_NORM);
  917.         r = random();
  918.         if (r < 0.25)
  919.             player_axe1 ();
  920.         else if (r<0.5)
  921.             player_axeb1 ();
  922.         else if (r<0.75)
  923.             player_axec1 ();
  924.         else
  925.             player_axed1 ();
  926.         self.attack_finished = time + 0.5;
  927.     }
  928.     else if (self.weapon == IT_SHOTGUN)
  929.     {
  930.         player_shot1 ();
  931.         W_FireShotgun ();
  932.         self.attack_finished = time + 0.5;
  933.     }
  934.     else if (self.weapon == IT_SUPER_SHOTGUN)
  935.     {
  936.         player_shot1 ();
  937.         W_FireSuperShotgun ();
  938.         self.attack_finished = time + 0.7;
  939.     }
  940.     else if (self.weapon == IT_NAILGUN)
  941.     {
  942.         player_nail1 ();
  943.     }
  944.     else if (self.weapon == IT_SUPER_NAILGUN)
  945.     {
  946.         player_nail1 ();
  947.     }
  948.     else if (self.weapon == IT_GRENADE_LAUNCHER)
  949.     {
  950.         player_rocket1();
  951.         W_FireGrenade();
  952.         self.attack_finished = time + 0.6;
  953.     }
  954.     else if (self.weapon == IT_ROCKET_LAUNCHER)
  955.     {
  956.         player_rocket1();
  957.         W_FireRocket();
  958.         self.attack_finished = time + 0.8;
  959.     }
  960.     else if (self.weapon == IT_LIGHTNING)
  961.     {
  962.         player_light1();
  963.         self.attack_finished = time + 0.1;
  964.         sound (self, CHAN_AUTO, "weapons/lstart.wav", 1, ATTN_NORM);
  965.     }
  966. };
  967.  
  968. /*
  969. ============
  970. W_ChangeWeapon
  971.  
  972. ============
  973. */
  974. void() W_ChangeWeapon =
  975. {
  976.     local    float    it, am, fl;
  977.     
  978.     it = self.items;
  979.     am = 0;
  980.     
  981.     if (self.impulse == 1)
  982.     {
  983.         fl = IT_AXE;
  984.     }
  985.     else if (self.impulse == 2)
  986.     {
  987.         fl = IT_SHOTGUN;
  988.         if (self.ammo_shells < 1)
  989.             am = 1;
  990.     }
  991.     else if (self.impulse == 3)
  992.     {
  993.         fl = IT_SUPER_SHOTGUN;
  994.         if (self.ammo_shells < 2)
  995.             am = 1;
  996.     }        
  997.     else if (self.impulse == 4)
  998.     {
  999.         fl = IT_NAILGUN;
  1000.         if (self.ammo_nails < 1)
  1001.             am = 1;
  1002.     }
  1003.     else if (self.impulse == 5)
  1004.     {
  1005.         fl = IT_SUPER_NAILGUN;
  1006.         if (self.ammo_nails < 2)
  1007.             am = 1;
  1008.     }
  1009.     else if (self.impulse == 6)
  1010.     {
  1011.         fl = IT_GRENADE_LAUNCHER;
  1012.         if (self.ammo_rockets < 1)
  1013.             am = 1;
  1014.     }
  1015.     else if (self.impulse == 7)
  1016.     {
  1017.         fl = IT_ROCKET_LAUNCHER;
  1018.         if (self.ammo_rockets < 1)
  1019.             am = 1;
  1020.     }
  1021.     else if (self.impulse == 8)
  1022.     {
  1023.         fl = IT_LIGHTNING;
  1024.         if (self.ammo_cells < 1)
  1025.             am = 1;
  1026.     }
  1027.  
  1028.     self.impulse = 0;
  1029.     
  1030.     if (!(self.items & fl))
  1031.     {    // don't have the weapon or the ammo
  1032.         sprint (self, "no weapon.\n");
  1033.         return;
  1034.     }
  1035.     
  1036.     if (am)
  1037.     {    // don't have the ammo
  1038.         sprint (self, "not enough ammo.\n");
  1039.         return;
  1040.     }
  1041.  
  1042. //
  1043. // set weapon, set ammo
  1044. //
  1045.     self.weapon = fl;        
  1046.     W_SetCurrentAmmo ();
  1047. };
  1048.  
  1049. /*
  1050. ============
  1051. CheatCommand
  1052. ============
  1053. */
  1054. void() CheatCommand =
  1055. {
  1056.     if (deathmatch || coop)
  1057.         return;
  1058.  
  1059.     self.ammo_rockets = 100;
  1060.     self.ammo_nails = 200;
  1061.     self.ammo_shells = 100;
  1062.     self.items = self.items | 
  1063.         IT_AXE |
  1064.         IT_SHOTGUN |
  1065.         IT_SUPER_SHOTGUN |
  1066.         IT_NAILGUN |
  1067.         IT_SUPER_NAILGUN |
  1068.         IT_GRENADE_LAUNCHER |
  1069.         IT_ROCKET_LAUNCHER |
  1070.         IT_KEY1 | IT_KEY2;
  1071.  
  1072.     self.ammo_cells = 200;
  1073.     self.items = self.items | IT_LIGHTNING;
  1074.  
  1075.     self.weapon = IT_ROCKET_LAUNCHER;
  1076.     self.impulse = 0;
  1077.     W_SetCurrentAmmo ();
  1078. };
  1079.  
  1080. /*
  1081. ============
  1082. CycleWeaponCommand
  1083.  
  1084. Go to the next weapon with ammo
  1085. ============
  1086. */
  1087. void() CycleWeaponCommand =
  1088. {
  1089.     local    float    it, am;
  1090.     
  1091.     it = self.items;
  1092.     self.impulse = 0;
  1093.     
  1094.     while (1)
  1095.     {
  1096.         am = 0;
  1097.  
  1098.         if (self.weapon == IT_LIGHTNING)
  1099.         {
  1100.             self.weapon = IT_AXE;
  1101.         }
  1102.         else if (self.weapon == IT_AXE)
  1103.         {
  1104.             self.weapon = IT_SHOTGUN;
  1105.             if (self.ammo_shells < 1)
  1106.                 am = 1;
  1107.         }
  1108.         else if (self.weapon == IT_SHOTGUN)
  1109.         {
  1110.             self.weapon = IT_SUPER_SHOTGUN;
  1111.             if (self.ammo_shells < 2)
  1112.                 am = 1;
  1113.         }        
  1114.         else if (self.weapon == IT_SUPER_SHOTGUN)
  1115.         {
  1116.             self.weapon = IT_NAILGUN;
  1117.             if (self.ammo_nails < 1)
  1118.                 am = 1;
  1119.         }
  1120.         else if (self.weapon == IT_NAILGUN)
  1121.         {
  1122.             self.weapon = IT_SUPER_NAILGUN;
  1123.             if (self.ammo_nails < 2)
  1124.                 am = 1;
  1125.         }
  1126.         else if (self.weapon == IT_SUPER_NAILGUN)
  1127.         {
  1128.             self.weapon = IT_GRENADE_LAUNCHER;
  1129.             if (self.ammo_rockets < 1)
  1130.                 am = 1;
  1131.         }
  1132.         else if (self.weapon == IT_GRENADE_LAUNCHER)
  1133.         {
  1134.             self.weapon = IT_ROCKET_LAUNCHER;
  1135.             if (self.ammo_rockets < 1)
  1136.                 am = 1;
  1137.         }
  1138.         else if (self.weapon == IT_ROCKET_LAUNCHER)
  1139.         {
  1140.             self.weapon = IT_LIGHTNING;
  1141.             if (self.ammo_cells < 1)
  1142.                 am = 1;
  1143.         }
  1144.     
  1145.         if ( (self.items & self.weapon) && am == 0)
  1146.         {
  1147.             W_SetCurrentAmmo ();
  1148.             return;
  1149.         }
  1150.     }
  1151.  
  1152. };
  1153.  
  1154. /*
  1155. ============
  1156. ServerflagsCommand
  1157.  
  1158. Just for development
  1159. ============
  1160. */
  1161. void() ServerflagsCommand =
  1162. {
  1163.     serverflags = serverflags * 2 + 1;
  1164. };
  1165.  
  1166. void() QuadCheat =
  1167. {
  1168.     if (deathmatch || coop)
  1169.         return;
  1170.     self.super_time = 1;
  1171.     self.super_damage_finished = time + 30;
  1172.     self.items = self.items | IT_QUAD;
  1173.     dprint ("quad cheat\n");
  1174. };
  1175.  
  1176. /*
  1177. ============
  1178. ImpulseCommands
  1179.  
  1180. ============
  1181. */
  1182. void() ImpulseCommands =
  1183. {
  1184.     if (self.impulse >= 1 && self.impulse <= 8)
  1185.         W_ChangeWeapon ();
  1186.  
  1187.     if (self.impulse == 9)
  1188.         CheatCommand ();
  1189.     if (self.impulse == 10)
  1190.         CycleWeaponCommand ();
  1191.     if (self.impulse == 11)
  1192.         ServerflagsCommand ();
  1193.  
  1194.     if (self.impulse == 255)
  1195.         QuadCheat ();
  1196.         
  1197.     self.impulse = 0;
  1198. };
  1199.  
  1200. /*
  1201. ============
  1202. W_WeaponFrame
  1203.  
  1204. Called every frame so impulse events can be handled as well as possible
  1205. ============
  1206. */
  1207. void() W_WeaponFrame =
  1208. {
  1209.     if (time < self.attack_finished)
  1210.         return;
  1211.  
  1212.     ImpulseCommands ();
  1213.     
  1214. // check for attack
  1215.     if (self.button0)
  1216.     {
  1217.         SuperDamageSound ();
  1218.         W_Attack ();
  1219.     }
  1220. };
  1221.  
  1222. /*
  1223. ========
  1224. SuperDamageSound
  1225.  
  1226. Plays sound if needed
  1227. ========
  1228. */
  1229. void() SuperDamageSound =
  1230. {
  1231.     if (self.super_damage_finished > time)
  1232.     {
  1233.         if (self.super_sound < time)
  1234.         {
  1235.             self.super_sound = time + 1;
  1236.             sound (self, CHAN_BODY, "items/damage3.wav", 1, ATTN_NORM);
  1237.         }
  1238.     }
  1239.     return;
  1240. };
  1241.  
  1242.  
  1243.